<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
import service from '@/utils/request'
export default {
  name: 'App',
  methods: {
    pollOrders() {
      setInterval(() => {
        // 向后端发送请求检查是否有新订单
        service.get('http://localhost:9090/order/checkOrders')
          .then(response => {
            const hasNewOrders = response.data;
            if (hasNewOrders.length !== 0) {
              console.log('New order received!',hasNewOrders);
              // 在这里处理新订单的逻辑
              // ...
              this.$notify.info({
          title: '提示',
          message: '您有新的订单',
          duration: 0
        });
            }
          })
          .catch(error => {
            console.error('Failed to check orders', error);
          });
      }, 6000); // 每10秒轮询一次，你可以根据实际需求调整时间间隔
    },
  },
  created() {
    // 在应用启动时调用轮询函数
    this.pollOrders();
  },
}
</script>
